using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Pages_Customer_CheckStatus : System.Web.UI.Page
{
    void Page_PreInit(Object sender, EventArgs e)
    {
        if (User.IsInRole("Admin"))
        {
            this.MasterPageFile = "~/Admin.master";
        }
        else if (User.IsInRole("Employee"))
        {
            this.MasterPageFile = "~/Employee.master";
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        txtDeliveryNumber.Focus();
    }

    protected void btnTrack_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            try
            {
                //Get the Customer ID of the Deliver
                int CustomerID = DALCheckStatus.GetCustomerID(Convert.ToInt32(txtDeliveryNumber.Text));
                //Get Contact Number of the User
                string ContactNumber = DALCheckStatus.GetCustomerContactNumber(CustomerID);
                //Compare the typed in Contact Number with the Customer's Contact Number
                if (txtContactNumber.Text.Trim().Equals(ContactNumber))
                {
                    //Give the typed in Delivery Number to the dtvStatus to show information
                    SqlDataSource1.SelectParameters.Clear();
                    SqlDataSource1.SelectParameters.Add("DeliverableID", txtDeliveryNumber.Text);
                    SqlDataSource1.DataBind();
                    Label1.Text = "";
                }
                else
                {
                    //Clear the dtvStatus Parameter
                    SqlDataSource1.SelectParameters.Clear();
                    SqlDataSource1.SelectParameters.Add("DeliverableID", "");
                    Label1.Text = "Please check your Delivery Number and Contact Number!";
                }
            }
            catch
            {
                Label1.Text = "Error tracking Delivery status!";
            }
        }
    }
}
